package com.example.campuslink.commen.adpter

import android.view.ViewGroup
import android.widget.TextView
import androidx.core.content.ContextCompat
import com.example.campuslink.BR
import com.example.campuslink.R
import com.example.campuslink.commen.core.CoreAdapter
import com.example.campuslink.commen.core.CoreViewHolder
import com.example.campuslink.databinding.AdapterProvinceBinding
import com.example.campuslink.viewModel.SchoolChoiceViewModel

class ProvinceAdapter(vm:  SchoolChoiceViewModel):CoreAdapter<AdapterProvinceBinding, SchoolChoiceViewModel, String>(
    BR.data,
    BR.viewModel,
    vm
) {
    override fun getItemLayoutId(viewType: Int): Int {
        return R.layout.adapter_province
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CoreViewHolder {
        return super.onCreateViewHolder(parent, viewType)
    }
    override fun onBindViewHolder(holder: CoreViewHolder, position: Int) {
        super.onBindViewHolder(holder, position)
        holder.binding.root.findViewById<TextView>(R.id.tv_province_name).text = mListData[position]
        holder.binding.root.findViewById<TextView>(R.id.tv_province_name).setOnClickListener({
            mViewModel?.setProvinceIndex(position)
            notifyDataSetChanged()
        })
        if (mViewModel?.provinceIndex?.value == position) {
            holder.binding.root.findViewById<TextView>(R.id.tv_province_name)
                .setTextColor(
                    ContextCompat.getColor(
                        holder.itemView.context,
                        R.color.color_orange_deep
                    )
                )
        } else {
            holder.binding.root.findViewById<TextView>(R.id.tv_province_name)
                .setTextColor(
                    ContextCompat.getColor(
                        holder.itemView.context,
                        R.color.color_5d5f5e
                    )
                )
        }
    }
}